package com.zxp01.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

import javax.xml.xpath.XPath;
import java.util.concurrent.TimeUnit;

public class Z02_Wait {
    /*三种等待方法*/
    WebDriver driver = new ChromeDriver();
    @Test
    public void wait3() throws InterruptedException {
        driver.get("https://www.baidu.com");

        // 1、强制等待，休眠线程
//        Thread.sleep(3000);         //休息三秒

        /* 2、隐式等待
          在设置的超时时间范围内不断查找元素，直到找元素或者超时*/
//        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

        /* 3、显示等待
        * 等到某个条件发生后再执行后续代码*/
        WebDriverWait wait = new WebDriverWait(driver,5);
        // 3.1、页面元素在当前页面存在并可见
//        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("su")));
        // 3.2、元素是否在页面上和能被点击
//        wait.until(ExpectedConditions.elementToBeClickable(By.id("su")));
        // 3.3、页面元素中包含特定的文本
//        WebElement p = driver.findElement(By.id("s-usersetting-top"));
//        wait.until(ExpectedConditions.textToBePresentInElement(p,"设置"));
        // 3.4、元素在页面存在
        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("su")));

        driver.close();
    }
}
